// Device/pages/HistoryInfo/components/bpgauge-component/index.js
import {
    logger
} from '@/utils/util'
import { customNavigate } from '@/utils/route'
const app = getApp();
const userMappings = {
    '本人': '_self',
    '配偶': '_mate',
    '子女': '_sons',
    '其他': '_other'
}
Component({
    properties: {
        params: {
            type: Object,
            default: null
        },
        data: {
            type: Object,
            default: null
        }
    },
    observers: {
        params(value) {
            logger.log(value)
            logger.log(this.data.data)
            const {
                dbp,
                sbp,
                pulse,
                measuring_time,
                user_tag
            } = value;
            const sbp_max = this.data.data[`sbp${userMappings[value['user_tag']]}`];
            const dbp_min = this.data.data[`dbp${userMappings[value['user_tag']]}`];
            const pulse_min = this.data.data[`pulse_min${userMappings[value['user_tag']]}`];
            const pulse_max = this.data.data[`pulse_max${userMappings[value['user_tag']]}`];
            this.setData({
                dbp,
                sbp,
                pulse,
                sbp_max,
                dbp_min,
                pulse_min,
                pulse_max,
                measuring_time,
                user_tag,
                state: dbp <= dbp_min && sbp <= sbp_max ? '正常血压' : '异常血压'
            })
        }
    },
    data: {
        staticPrefix: app.globalData.STATIC_PREFIX
    },
    methods: {
        onNavigateToAnalysis() {
            customNavigate({
                url: `/Device/pages/Analysis/index`,
                params: {
                    device_imei: this.data.params.device_imei
                }
            })
        }
    }
})